/**
 * (created at 2011-1-30)
 */
package qiushuo.mysqlparser.ast.fragment;

import java.sql.SQLSyntaxErrorException;
import java.util.ArrayList;
import java.util.List;

import qiushuo.mysqlparser.ast.ASTNode;
import qiushuo.mysqlparser.ast.expression.Expression;
import qiushuo.mysqlparser.generator.SQLType;
import qiushuo.mysqlparser.util.Pair;

/**
 * @author <a href="mailto:QiuShuo1985@gmail.com">QIU Shuo</a>
 */
public class GroupBy implements ASTNode {
    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected static List ensureListType(List list) throws SQLSyntaxErrorException {
        if (list == null || list.size() <= 0) {
            throw new SQLSyntaxErrorException("at least one element should be contained after GROUP BY");
        }
        if (list instanceof ArrayList) return list;
        return new ArrayList(list);
    }

    /** boolean: isDesc */
    private final List<Pair<Expression, Boolean>> groups;
    private final boolean withRollup;

    @SuppressWarnings("unchecked")
    public GroupBy(List<Pair<Expression, Boolean>> groups, boolean withRollup) throws SQLSyntaxErrorException {
        this.groups = ensureListType(groups);
        this.withRollup = withRollup;
    }

    @Override
    public String generateSql(SQLType type) {
        // QS_TODO gen sql
        throw new UnsupportedOperationException("not implemented yet");
    }

}
